package leetcode.n2022;

/**
 * https://leetcode-cn.com/problems/reverse-prefix-of-word/
 * 2000. 反转单词前缀
 *
 * @program: brushing
 * @description:
 * @author: LiuQiang
 * @create: 2022-02-03
 **/
public class ReversePrefix {

    public String reversePrefix(String word, char ch) {
        String a = "";
        String b = "";
        for (int i = 0; i < word.length(); i++) {
            a += word.charAt(i);
            b += word.charAt(i);
            if (word.charAt(i) == ch) {
                b = "";
                ch = 'A';
                for (int j = a.length() - 1; j >= 0; j--) {
                    b += a.charAt(j);
                }
            }
        }

        return b;
    }

    public static void main(String[] args) {
        String word = "abcdefd";
        char ch = 'd';

        System.out.println(new ReversePrefix().reversePrefix(word, ch));
    }
}
